<template>
	<view class="main psb">
		<u-navbar height="55">
			<u-search style="margin: 0 20rpx;" placeholder="搜索" :show-action="false" @search="search"
				v-model="all.searchValue"></u-search>
		</u-navbar>
		<view style="padding: 20rpx;">
			<view class="flex flex-ai-c">
				<view class="head-img" style="margin-right: 20rpx;">
					<image :src="all.userinfo.handimg" style="border-radius: 12rpx;"></image>
				</view>
				<view>
					<view>#{{all.userinfo.title}}#</view>
					<view>{{all.userinfo.username}}</view>
					<view>发布数：{{all.userinfo.publish_num}} 阅读数：{{all.userinfo.readimg_num}}</view>
				</view>
			</view>
			<view>导语：{{all.userinfo.introduction}}</view>
		</view>
		<u-line margin="20rpx" :hair-line="false"></u-line>
		<list @giveLike="giveLike" :swiperCurrent="all.swiperCurrent" :list="all.list" @onAbort="onAbort"
			@onRefresh="onRefresh" @onRestore="onRestore" :triggered="triggered">
		</list>
	</view>
</template>

<script lang="ts" setup>
	import user from '@/api/user.js'
	import {
		reactive, ref
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import article from '@/api/article.js'
	import list from '@/components/detail_list.vue'
	interface userFace {
		[propName : string] : any
	}
	let _triggered = ref(false)
	let triggered = ref(false)
	let all = reactive<userFace>({
		id: null,
		searchValue: '',
		list: [],
		swiperCurrent: 0,
		userinfo: {}
	})
	const search = () => {

	}
	const getEntryList = async (id : string | number, type : string | number) => {
		const res = await article.getEntryList({
			page: 1,
			pageSize: 50,
			searchValue: '',
			id: id,
			type: type
		})

		all.userinfo = res.data[0] || []
	}
	const getArticleList = async (entryid, cb = () => { }) => {
		const res = await user.getArticleList({
			page: 1,
			pageSize: 50,
			// searchValue: all.searchValue,
			entryid: entryid
		})
		all.list = res.data
		cb()
	}
	const giveLike = () => {
		getArticleList(all.id)
	}
	//中止触发
	const onAbort = () => {
		triggered.value = false
	}
	//刷新触发
	const onRefresh = () => {
		if (_triggered.value) return
		_triggered.value = true
		if (!triggered.value) triggered.value = true
		getArticleList(all.id, () => {
			triggered.value = false
			_triggered.value = false
		})
	}
	//复位
	const onRestore = () => {
		triggered.value = false
		_triggered.value = false
	}
	onLoad((op) => {
		all.id = op.id
		all.searchValue = op.title
		getArticleList(op.id)
		getEntryList(op.id, op.type)
	})
</script>

<style>
</style>